package jxtend.processor.eclipse.utils;

import jxtend.processor.eclipse.JxtendProcessor;
import net.sf.cglib.proxy.Enhancer;
import net.sf.cglib.proxy.MethodInterceptor;

public final class CGLibProxyUtils {
	public static <T> T createFromProxy(Class<T> clazz, MethodInterceptor methodInterceptor) {
		Enhancer cglibEnhancer = new Enhancer();
		cglibEnhancer.setSuperclass(clazz);
		cglibEnhancer.setClassLoader(JxtendProcessor.class.getClassLoader());
		cglibEnhancer.setCallback(methodInterceptor);
	
		@SuppressWarnings("unchecked")
		T result = (T) cglibEnhancer.create();
		return result;
	}

	private CGLibProxyUtils() {
		// Utility class
	}
}
